import { UserService } from 'src/app/@core/services/user/user.service';
import { StorehouseService } from 'src/app/@core/services/storehouse/storehouse.service';
import { Component, Input } from '@angular/core';
import { DialogService, TableWidthConfig } from 'ng-devui';
import { AddPositionDataComponent } from './add-position-data/add-position-data.component';
import { stroehouseitem } from 'src/app/@core/data/storeHouse';
@Component({
  selector: 'app-positiondata',
  templateUrl: './positiondata.component.html',
  styleUrls: ['./positiondata.component.scss']
})
export class PositiondataComponent {
  @Input() data: any;
  basicDataSource:stroehouseitem[]=[];
  dataTableOptions = {
    columns: [
      {
        field: 'bianma',
        header: '编码',
        fieldType: 'text'
      },
      {
        field: 'name',
        header: '名称',
        fieldType: 'text'
      },
      {
        field: 'enabled',
        header: '状态',
        fieldType: 'text'
      }
    ]
  }
  tableWidthConfig: TableWidthConfig[] = [
    {
      field: '#',
      width: '50px'
    },
    {
      field: 'firstName',
      width: '150px'
    },
    {
      field: 'gender',
      width: '150px'
    },
    {
      field: 'gender',
      width: '150px'
    }
  ];
  config = {
    id: 'dialog-service',
    width: '346px',
    maxHeight: '600px',
    title: 'Start Snapshot Version',
    content: AddPositionDataComponent,
    backdropCloseable: true,
    data: {
      name: 'Tom',
      age: 10,
      address: 'Chengdu',
    },
  };
  msgs: any;
  constructor(private dialogService: DialogService,private StorehouseService:StorehouseService,private UserService:UserService) {}
  ngOnInit(): void {
    this.StorehouseService.getWarehousePositionsByWarehouseId(this.data.rowItem.warehouseId,1,999).subscribe((res:any)=>{
      this.basicDataSource = res.items
    })
  }
  addPosition(dialogtype?:any){
    let data ={
      warehouseId:this.data.rowItem.warehouseId,
      display:false
    }
    const results = this.dialogService.open({
      ...this.config,
      title: '新增仓位',
      dialogtype: dialogtype,
      data: data,
      buttons: [
        {
          cssClass: 'primary',
          text: '确定',
          disabled: false,
          handler: ($event: Event) => {
            if(results.modalContentInstance.positionData.positionNum && results.modalContentInstance.positionData.positionName){
              this.StorehouseService.createPosition(results.modalContentInstance.positionData).subscribe((res:any)=>{
                this.StorehouseService.getWarehousePositionsByWarehouseId(this.data.rowItem.warehouseId,1,999).subscribe((res:any)=>{
                  this.basicDataSource = res.items
                })
                results.modalInstance.hide();
              }
              )
            }else{
              data.display = true
            }
          },
        },
        {
          id: 'btn-cancel',
          cssClass: 'common',
          text: '取消',
          handler: ($event: Event) => {
            results.modalInstance.hide();
          },
        },
      ],
    });
  }
  showToast(type: any,summary:any,content:any) {
    switch (type) {
    default:
      this.msgs = [{ severity: type, summary: summary, content: content }];
    }
  }//提示框
}
